
<template>
	<!-- 添加弹框 -->
	<el-dialog title="" visible :show-close="false" :append-to-body="true" class="wrap" @close="cancel" :close-on-click-modal="false">
		<i class="el-icon-close close" @click="cancel" style="color: white;z-index:10;"></i>
	    <div class="bt">领用</div>
	     <el-form label-width="100px" class="form">
	     <el-form-item label="物品名称">
			<el-input v-model="vwpid"  placeholder="请选择物品名称" icon="add" class="input"v-if="false" ></el-input>
			<el-input v-model="vwpidmc" placeholder="请选择物品名称" icon="add" class="input" :readonly="true"></el-input>
			<el-button size='small'  @click="componentsShow('xzwp')" >选择物品</el-button>
		</el-form-item>
		<el-form-item label="库存数量">
			<el-input v-model="vkcsl" :readonly="true" icon="add" class="input1"></el-input>
 		</el-form-item>
		<el-form-item label="领用人">
			 <el-select v-model="vlsid" class="input1" >
            <el-option :label="v.zwm" :value="v.id" v-for="v in comboxlist"></el-option>
      </el-select>
		</el-form-item>
		<el-form-item label="领用数量">
			<el-input v-model="lysl" placeholder="请输入领用数量" icon="add" class="input1"></el-input>
 		</el-form-item>
		<el-form-item label="领用原因">
			<el-input v-model="vlyyy"  type="textarea" :rows="4" placeholder="请输入领用原因" icon="add" class="input1"></el-input>
 		</el-form-item>

		<!-- <Wpchooselist class="wpfl" @wpchoose="wpchooseed" @close="wpchoosecancel" v-if="showchoselist"  ></Wpchooselist> -->
		<Xzwplist v-if="portComponents.xzwp.toggle"  @close="componentsHide"  :data="portComponents.xzwp.data" :params="this.wpfl"></Xzwplist>
        <div class="an" style="text-align: center;">
		<el-button type="primary" class="submit" v-if='tj' @click="submit">添加</el-button>
		<el-button type="danger" class="submit" @click="cancel">退出</el-button>
		</div>
	</el-form>
	</el-dialog>
</template>
<script type="text/javascript">
	import qs from 'qs'
	// import Wpchooselist from '../wpfx/wpchooselist'
	import Xzwplist from '../bs/xzwp'

	export default {
		props: ['params'],
		 components: { Xzwplist},
		data() {
			return {
				tj:true,
				showchoselist:false,
				vwpid: '',
				vkcsl:'',
				vwpidmc:'',
				vlsid: '',
				lysl: '',
				vlyyy: '',
				// vlyckid: '',
				comboxlist:[],
				dialogTableVisible: true,
				portComponents: {
						xzwp : {
								type: 'xzwp',
								toggle: false,
								params: '',
								data: {}
						}
				},
			}
		},
		 created(){
		 	this.wpfl=this.params;
		 this.getcomboxlist();
	 },
	 watch:{
//          'lysl': function(newVal,oldVal){
//              if(parseInt(newVal) > parseInt(this.vkcsl)) {//如果小于等于零
//                   this.$message.warning('输入的领用数量超过库存数量并且不能为0!')
//                   this.tj=false
//              }
//          }
        },
		methods: {
			submit() {
				//检测
				this.$store.state.loading = true;
			    if(this.lysl=='0') {
					this.$message.warning('领用数量不能为0！');
					this.$store.state.loading = false;
					return;
				}else if(!this.vwpid){
                    this.$message.warning('请选择物品名称');
					this.$store.state.loading = false;
                    return;
                }
				else if(!this.vlsid){
                    this.$message.warning('请选择领用人');
					this.$store.state.loading = false;
                    return;
                }
				else if(!this.vlyyy){
                    this.$message.warning('请填写领用原因');
					this.$store.state.loading = false;
                    return;
                }
				var logininfo = JSON.parse(localStorage.logininfo);
				var params3 = qs.stringify({
					wpid: this.vwpid,
					cnt:this.lysl,
					lyr: this.vlsid,
					note: this.vlyyy,
					yhid: logininfo.id,
					xxid:logininfo.xxid
				});
				//执行
				this.axios.post(this.$store.state.api + 'lyck/insert', params3)
					.then(res => {
						if(res.data.code == 1) {
							this.$emit('close', { type: 'add', cancel: false });
							this.$message.success(res.data.msg);
							this.$store.state.loading = false;
						} else {
							this.$message.warning(res.data.msg);
							this.$store.state.loading = false;
						}
					}).catch(res => {
						this.$message.danger("服务器繁忙，请重试");
						this.$store.state.loading = false;
					})
			},
//			showwp(){
//				this.showchoselist =true;
//			},
//			wpchooseed(josndata){
//				this.vwpidmc = josndata.wpmc;
//				this.vwpid=josndata.wpid;
//						this.showchoselist=false;
//			},
//			wpchoosecancel(){
//						this.showchoselist=false;
//			},
			cancel() {
				this.$emit('close', { type: 'add', cancel: true })
			},
		getcomboxlist(){
        var logininfo = JSON.parse(localStorage.logininfo) ;
				var params3 = qs.stringify({
					xxid:logininfo.xxid
				});
          this.searchLoading = true;
          this.axios.post(this.$store.state.api + 'ls/mc',params3)
		 .then( res => {
                        let data = res.data.data;
						let list = data;
						this.comboxlist = list;
          }).catch( res => {
              this.searchLoading = false;
          })
        },
				componentsShow (type,data) { //显示组件
						console.log(type,data)
						for ( let i in this.portComponents ) {
								if (type == this.portComponents[i].type) {
										console.log(this.portComponents[i])

										this.portComponents[i].toggle = true;
										this.portComponents[i].params = data;

										if (this.portComponents[i].data.type == 'single') {
												this.portComponents[i].data.index = data.row.id

										}else if(this.portComponents[i].data.type == 'multiple'){
												this.portComponents[i].data.index = this.multipleDelNum;

										}else{
												return;
										}
										return;
								}
						}

				},
				componentsHide (setting) { //关闭组件
						if(setting.data){
								this.vwpidmc = setting.data[0].mc
								this.vwpid = setting.data[0].id
								this.vkcsl = setting.data[0].kcsl
								
								// this.vje = setting.data[0].jg
								for ( let i in this.portComponents ) {
										if (setting.type == this.portComponents[i].type) {
												this.portComponents[i].toggle = false;
												if (this.portComponents[i].type == 'singleDelete') {
														this.dataList.splice(setting.index,1)
												}
												if (!setting.cancel) {
													 // this.search();
														if (setting.type == "student") {
																this.student = setting.data.zwm + ' - ' + setting.data.xh
																this.studentid = setting.data.id
														}else{

																setting.data.forEach( (v) => {

														 var iscan =true;
														 for ( let z in this.dataList ) {
															console.log(z,v.id );
															if(this.dataList[z].id==v.id){
																iscan =false;
																break;
															}
														 }
							if (iscan){
															 // this.dataList.push(v);
															}
														})
														}
												}
												return;
										}
								}
						}else{
							for ( let i in this.portComponents ) {
			                    if (setting.type == this.portComponents[i].type) {
			                        this.portComponents[i].toggle = false;
			                        if (!setting.cancel) {

			                        }
			                        return;
			                    }
			                }
						}

						}
						},
	}
</script>
<style lang="less" scoped>
	.wrap {
		.input-block {
			margin-bottom: 20px;
			text-align: center;
		}
		.bt{
		position: absolute;
		width: 100%;
		height: 50px;
		margin: 0 auto;
		top: 0;
		left: 0;
		background: #50BFFF;
		color:white;
		text-align:left;
		line-height: 50px;
		font-size: 17px;
		padding-left: 15px;
	}

.form {
	text-align: left;
	margin-top: 10px;
	/*margin-left: 10%;*/
}
		.input {
			width: 75%;
			display: inline-block;
		}
		.input1 {
			width: 90%;
			display: inline-block;
		}
		/*.input2 {
			width: 90;
			display: inline-block;
			vertical-align: middle;
		}*/
		.input-block span {
			display: inline-block;
			width: 100px;
			text-align: right;
		}
		.select-block {
	// display: block;
	float: left;
	width: 85%;
}
		.submit {
			width: 120px;

		}
		.wpfl{
			background: #fff;
			position: absolute;
			top: 5px;
			left: 5px;
		}
	}
</style>
